package com.motu.monstercity.server.game.logic;

import com.motu.monstercity.server.game.userdata.*;
import com.motu.vertx.module.utility.model.EntityManager;
import com.motu.vertx.module.utility.model.Model;
import com.motu.vertx.module.utility.toolset.TimeUtils;

import java.util.ArrayList;
import java.util.List;

public class FightUserData extends FightBaseData {
    public static UserStage getUserStage(long userId) {
        return (UserStage) EntityManager.getUniqueEntity(UserStage.class, userId);
    }

    // 未解锁兽潮入侵功能，则返回null
    public static UserMonsterTideInfo getUserMonsterTiedInfo (long userId) {
        return (UserMonsterTideInfo) EntityManager.getUniqueEntity(UserMonsterTideInfo.class, userId, false);//
    }

    public static UserSnatchInfo getUserSnatchInfo(long userId) {
        return (UserSnatchInfo) EntityManager.getUniqueEntity(UserSnatchInfo.class, userId);
    }

    public static UserSnatchScore getUserSnatchScore(long userId) {
        return (UserSnatchScore) EntityManager.getUniqueEntity(UserSnatchScore.class, userId);
    }

    // 获取UserSnatchPartner列表
    public static List<UserSnatchPartner> getUserSnatchPartnerList(long userId) {
        List<UserSnatchPartner> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserSnatchPartner.class, userId)) {
            UserSnatchPartner entity = (UserSnatchPartner) model;
            list.add(entity);
        }
        return list;
    }

    // 获取物资争夺的UserSnatchPartner数据，没有则创建
    public static UserSnatchPartner getUserSnatchPartner(long userId, int partnerId) {
        UserSnatchPartner userSnatchPartner = (UserSnatchPartner) EntityManager.getEntity(UserSnatchPartner.class, userId, partnerId);
        if (userSnatchPartner == null) {
            userSnatchPartner = new UserSnatchPartner();
            userSnatchPartner.putUserId(userId);
            userSnatchPartner.putPartnerId(partnerId);
            userSnatchPartner.putResetTime(TimeUtils.getCurTime());// 避免该干员第一次上场,打完重登,重置数据
            userSnatchPartner.doCreate();
        }
        return userSnatchPartner;
    }

    public static ServerSnatchFame getServerSnatchFame(long userId, long dbid) {
        return (ServerSnatchFame) EntityManager.getEntity(ServerSnatchFame.class, userId, dbid);
    }
    public static List<ServerSnatchFame> getServerSnatchFameList(int serverId) {
        List<ServerSnatchFame> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(ServerSnatchFame.class, serverId)) {
            ServerSnatchFame entity = (ServerSnatchFame) model;
            list.add(entity);
        }
        return list;
    }

    public static UserSnatchTeam getUserSnatchTeam(long userId, int teamId) {
        return (UserSnatchTeam) EntityManager.getEntity(UserSnatchTeam.class, userId, teamId);
    }

    public static List<UserSnatchTeam> getUserSnatchTeamList(long userId) {
        List<UserSnatchTeam> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserSnatchTeam.class, userId)) {
            UserSnatchTeam entity = (UserSnatchTeam) model;
            list.add(entity);
        }
        return list;
    }

    // 物资争夺战报
    public static List<UserSnatchRecord> getUserSnatchRecordList(long userId) {
        List<UserSnatchRecord> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserSnatchRecord.class, userId)) {
            UserSnatchRecord entity = (UserSnatchRecord) model;
            list.add(entity);
        }
        return list;
    }

    public static UserSnatchRecord getUserSnatchRecord(long userId, long dbid) {
        return (UserSnatchRecord) EntityManager.getEntity(UserSnatchRecord.class, userId, dbid);
    }

    public static List<UserSnatchEnemy> getUsersnatchEnemyList(long userId) {
        List<UserSnatchEnemy> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(UserSnatchEnemy.class, userId)) {
            UserSnatchEnemy entity = (UserSnatchEnemy) model;
            list.add(entity);
        }
        return list;
    }

    public static UserSnatchEnemy getUserSnatchEnemy(long userId, long dbid) {
        return (UserSnatchEnemy) EntityManager.getEntity(UserSnatchEnemy.class, userId, dbid);
    }

    public static List<ServerSnatchOffer> getServerSnatchOfferList(int serverId) {
        List<ServerSnatchOffer> list = new ArrayList<>();
        for (Model model : EntityManager.getEntityList(ServerSnatchOffer.class, serverId)) {
            ServerSnatchOffer entity = (ServerSnatchOffer) model;
            list.add(entity);
        }
        return list;
    }

    public static ServerSnatchOffer getServerSnatchOffer(int serverId, long userId) {
        return (ServerSnatchOffer) EntityManager.getEntity(ServerSnatchOffer.class, serverId, userId);
    }
}
